#!/bin/bash
# triangle.sh: this simple script can print a triangle profile
# Written by Stone Liu. 2012-05-29 17:53
#

read -p "Please input a positive number:" LINE

# This function is controlling the space...

draw_space() {
	for (( SPACE=$LINE-$CUR_LINE ; SPACE>=0 ; SPACE-- ))
	do
		if [ $SPACE -eq 0 ]
		then
			break
		fi
		echo -n " "
	done
}

# This function is controlling the star...

draw_star() {
	for (( STAR=0 ; STAR<2*$CUR_LINE-1 ; STAR++ ))
	do
		echo -n "*"
	done
}

# This is the main function...

for (( CUR_LINE=1 ; CUR_LINE<=$LINE ; CUR_LINE++ ))
do
	draw_space	#  invoke the draw_space function
	draw_star	#  invoke the draw_star function
	echo		## new line
done


